package com.hm.myrecyclervview

import android.annotation.SuppressLint
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView

class MainActivity : AppCompatActivity() {
    @SuppressLint("MissingInflatedId")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }


        val myRecyclerView = findViewById<RecyclerView>(R.id.myrecyclerview)
        myRecyclerView.layoutManager = LinearLayoutManager(this)
        myRecyclerView.addItemDecoration(MyDecoration(this))
        myRecyclerView.adapter = MyAdapter(this,initdata())
    }

    private fun initdata(): ArrayList<MyData> {

        val  myDatalist = ArrayList<MyData>()

        for ( i in  1..4){
            for (j in 1 .. 10){

                myDatalist.add(MyData("id$j" , "组$i"))
            }

        }
        return myDatalist
    }
}